﻿Shader "Dan/UI/UI_RotateCircle"
{
    Properties
    {
        _ColorStart ("ColorStart", Color) = (0,1,0.6039999,1)
        _ColorEnd ("ColorEnd", Color) = (0.07843138,0.3921569,0.7843137,1)
        _Emission ("Emission", Float ) = 1
        _CircleStep ("CircleStep", Float ) = 8
        _Width ("Width", Range(0, 1)) = 0.8
        _Length ("Length", Range(0, 1)) = 0.5
        _Speed ("Speed", Float ) = 0.5
        _MaskOutside ("MaskOutside", Range(0, 1)) = 1
        _MaskInside ("MaskInside", Range(0, 1)) = 1
        _RandomSeed ("RandomSeed", Float ) = 0.3
        _MaskRandom ("MaskRandom", Range(0, 1)) = 0

    }
    
    SubShader
    {

        Tags { "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent" }
        LOD 100    
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off 
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            #include "../ShaderLibs/UIFX.cginc"
            #include "../ShaderLibs/UVOperator.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct v2f
            {
                float4 vertex : SV_POSITION;    
                float2 uv : TEXCOORD0;
                
            };

             float4 _ColorEnd;
             float _CircleStep;
             float _Width;
             float _Speed;
             float _RandomSeed;
             float _Length;
             float _MaskOutside;
             float _MaskInside;
             float4 _ColorStart;
             float _Emission;
             float _MaskRandom;
            
            v2f vert ( appdata v )
            {
                
                v2f o;
                UNITY_INITIALIZE_OUTPUT(v2f ,o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                
                o.uv = v.uv;        
                return o;
            }
            
            

            fixed4 frag (v2f i ) : SV_Target
            {
                
                float2 uv = i.uv;
                float2 ruv = uv*2-1;

                float circle = length(ruv);//求圆
                float polar =DrawPolar(ruv);//求极坐标
                
                float flick = ShapeSteps(circle,_CircleStep,_RandomSeed);//求随机分割的圆形
                
               

                float polarLayer = frac((flick+polar)-(_Time.y*_Speed*(flick*2-1)));//随极坐标旋转滚动产生旋转效果

                float widthVal =step(frac(_CircleStep*circle),_Width);//分层圆的宽度
                
                float maskFinal = DrawRing(circle,_MaskOutside,_MaskInside);//求环形遮罩

                float maskRD =step(_MaskRandom,flick);//随机遮罩

                float finalAlpha =step(1-_Length,(widthVal*polarLayer*maskFinal*maskRD));//长度

                clip(finalAlpha - 0.5);//剔除

                float3 finalColor = lerp(_ColorStart.rgb,_ColorEnd.rgb,polarLayer)*_Emission;
                
                return fixed4(finalColor,1);
                

                


                
                
            }
            ENDCG
        }
    }
    
    
    
}
